﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Reflection.PortableExecutable;

namespace EGS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MachineroomController : ControllerBase
    {
        private readonly EGSDbContext db;
        public MachineroomController(EGSDbContext context)
        {
            db = context;
        }


        public List<EGS_Machine_room> GetAll()
        {
            return db.Machine_Rooms.ToList();
        }

        public EGS_Machine_room? GetEGS_Machine_RoomById(Guid id)
        {
            EGS_Machine_room? machine_Room = new EGS_Machine_room();
            machine_Room = db.Machine_Rooms.Where(u => u.ID == id).FirstOrDefault();
            return machine_Room;
        }

        //[HttpPost]
        //public Result AddMachine_Room([FromBody] EGS_User Machine_Room)
        //{
        //    Result result = new Result();
        //    db.Machine_Rooms.Add(Machine_Room);
        //    result.Data = db.SaveChanges();
        //    return result;
        //}
        [HttpPut]
        public Result UpMachiner_Room([FromBody] EGS_User user)
        {
            Result result = new Result();
            EGS_Machine_room Machiner_Room = null;
            db.Machine_Rooms.Update(Machiner_Room);
            result.Data = db.SaveChanges();

            return result;
        }
        //[HttpGet]
//        public Result Get(Guid id)
//        {
//            Result result = new Result();
//            result.Data = db.Machine_Rooms.Where(w => w.ID == id).FirstOrDefault();
//=======

        [HttpPost]
        public Result AddMachiner_Rooms([FromBody] EGS_Machine_room machine_Room)
        {
            Result result = new Result();
            db.Machine_Rooms.Add(machine_Room);
            result.Data = db.SaveChanges();
            return result;
        }

        [HttpPut]
        public Result UpMachiner_Rooms([FromBody] EGS_Machine_room machine_Room)
        {
            Result result = new Result();
            db.Machine_Rooms.Update(machine_Room);
            result.Data = db.SaveChanges();
            return result;
        }

        [HttpGet]
        public Result Get(Guid id)
        {
            Result result = new Result();
            result.Data = db.Machine_Rooms.Where(w => w.ID == id).FirstOrDefault();
            return result;
        }
        //public List<EGS_Machine_room> GetAll()
        //{
        //    return db.Machine_Rooms.ToList();
        //}
        //public EGS_Machine_room? GetEGS_Machine_RoomById(Guid id)
        //{
        //    EGS_Machine_room? machine_Room = new EGS_Machine_room();
        //    machine_Room = db.Machine_Rooms.Where(u => u.ID == id).FirstOrDefault();
        //    return machine_Room;
        //}



        //[HttpGet]
        //public Result Get(Guid id)
        //{
        //    Result result = new Result();
        //    result.Data = db.Machine_Rooms.Where(w => w.ID == id).FirstOrDefault();


        //    return result;
        //}



    }
}
